package com.zjj;

import org.apache.dubbo.config.annotation.Reference;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

import java.util.concurrent.CompletableFuture;

@SpringBootApplication
public class DubboConsumerDemo  {

  //@Reference注解就是用于标记这个服务具体使用了生产者的哪个接口实现
    @Reference(version = "default")
    private DemoService demoService;

    public static void main(String[] args)  {
        ConfigurableApplicationContext context = SpringApplication.run(DubboConsumerDemo.class);
        DemoService demoService = context.getBean(DemoService.class);

        // 调用直接返回CompletableFuture
        CompletableFuture<String> future = demoService.sayHelloAsync("异步调用");  // 5

        System.out.println("1.在执行别的业务逻辑......");

        future.whenComplete((v, t) -> {
            if (t != null) {
                t.printStackTrace();
            } else {
                System.out.println("3.异步调用provider结果 : " + v);
            }
        });

        System.out.println("2.结束了");

    }

}
